package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.MyFollowsShowData;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 16/9/12.
 */
public class MyFollowsShowAdapter extends RecyclerView.Adapter<MyFollowsShowAdapter.ViewHolder> {
    private Context context;
    private MyFollowsShowData myFollowsShowData;

    public MyFollowsShowAdapter(Context context, MyFollowsShowData myFollowsShowData) {
        this.context = context;
        this.myFollowsShowData = myFollowsShowData;
    }

    @Override
    public MyFollowsShowAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv_hotrecommend, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyFollowsShowAdapter.ViewHolder holder, int position) {
        Picasso.with(context).load(myFollowsShowData.getData().getList().get(position).getAuthor().getAvatar()).config(Bitmap.Config.RGB_565).into(holder.civ_header_hotrecommend);
        holder.tv_author_hotrecommend.setText(myFollowsShowData.getData().getList().get(position).getAuthor().getNickname());
        holder.tv_datestr_hotrecommend.setText(myFollowsShowData.getData().getList().get(position).getDatestr());
        holder.tv_content_hotrecommend.setText(myFollowsShowData.getData().getList().get(position).getContent());
        holder.tv_peoplelikes_hotrecommend.setText(myFollowsShowData.getData().getList().get(position).getDynamic().getLikes() + "人喜欢");
        Picasso.with(context).load(myFollowsShowData.getData().getList().get(position).getMiddle_pic_url()).config(Bitmap.Config.RGB_565).into(holder.iv_bigpic_hotrecommend);
    }

    @Override
    public int getItemCount() {
        return myFollowsShowData.getData().getList().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private CircleImageView civ_header_hotrecommend, civ_myheader_hotrecommend;
        private TextView tv_author_hotrecommend, tv_datestr_hotrecommend, tv_content_hotrecommend, tv_peoplelikes_hotrecommend;
        private ImageView iv_bigpic_hotrecommend;

        public ViewHolder(View itemView) {
            super(itemView);
            civ_header_hotrecommend = (CircleImageView) itemView.findViewById(R.id.civ_header_hotrecommend);
            //civ_myheader_hotrecommend = (CircleImageView) itemView.findViewById(R.id.civ_myheader_hotrecommend);
            tv_author_hotrecommend = (TextView) itemView.findViewById(R.id.tv_author_hotrecommend);
            tv_datestr_hotrecommend = (TextView) itemView.findViewById(R.id.tv_datestr_hotrecommend);
            tv_content_hotrecommend = (TextView) itemView.findViewById(R.id.tv_content_hotrecommend);
            tv_peoplelikes_hotrecommend = (TextView) itemView.findViewById(R.id.tv_peoplelikes_hotrecommend);
            iv_bigpic_hotrecommend = (ImageView) itemView.findViewById(R.id.iv_bigpic_hotrecommend);
        }
    }
}
